<?php

include dirname( __FILE__ )."/header.php";
$myts =& MyTextSanitizer::getInstance(); // MyTextSanitizer object

if (!empty($_POST['submit'])) {
	if (empty($xoopsUser)) {
		$sender = 0;
	} else {
		$sender = $xoopsUser->getVar('uid');
	}
	$ip = getenv("REMOTE_ADDR");
	$lid = intval($_POST['lid']);
	if ( $sender != 0 ) {
		// Check if REG user is trying to report twice.
		$result=$xoopsDB->query("SELECT COUNT(*) FROM ".$xoopsDB->prefix($mydirname."_broken")." WHERE lid=$lid AND sender=$sender");
		list ($count)=$xoopsDB->fetchRow($result);
		if ( $count > 0 ) {
			redirect_header("index.php",2,_MD_MYDOWNLOADS_ALREADYREPORTED);
			exit();
		}
	} else {
		// Check if the sender is trying to vote more than once.
		$result=$xoopsDB->query("SELECT COUNT(*) FROM ".$xoopsDB->prefix($mydirname."_broken")." WHERE lid=$lid AND ip = '$ip'");
		list ($count)=$xoopsDB->fetchRow($result);
		if ( $count > 0 ) {
			redirect_header("index.php",2,_MD_MYDOWNLOADS_ALREADYREPORTED);
			exit();
		}
	}
	$newid = $xoopsDB->genId($xoopsDB->prefix($mydirname."_broken")."_reportid_seq");
    $sql = sprintf("INSERT INTO %s (reportid, lid, sender, ip) VALUES (%u, %u, %u, '%s')", $xoopsDB->prefix($mydirname."_broken"), $newid, $lid, $sender, $ip);
	$xoopsDB->query($sql) or exit();
	$tags = array();
	$tags['BROKENREPORTS_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/index.php?op=listBrokenDownloads';
	$notification_handler =& xoops_gethandler('notification');
	$notification_handler->triggerEvent('global', 0, 'file_broken', $tags);
	redirect_header("index.php",2,_MD_MYDOWNLOADS_THANKSFORINFO);
	exit();
} else {
	$xoopsOption['template_main'] = $mydirname.'_brokenfile.html';
	include XOOPS_ROOT_PATH.'/header.php';
//wanikoo
$mydownloads_module_header = '';
$mydownloads_module_header .= '
	<link rel="stylesheet" type="text/css" href="'.mydownloadsGetStyleURL("mydownloads.css").'" />
	<script src="'.mydownloadsGetStyleURL("mydownloads.js").'" type="text/javascript"></script>
	';
$mydownloads_module_header = $mydownloads_module_header; 
$xoopsTpl->assign('xoops_module_header', $mydownloads_module_header);
//

	$xoopsTpl->assign('lang_reportbroken', _MD_MYDOWNLOADS_REPORTBROKEN);
	$xoopsTpl->assign('file_id', intval($_GET['lid']));
	$xoopsTpl->assign('lang_thanksforhelp', _MD_MYDOWNLOADS_THANKSFORHELP);
	$xoopsTpl->assign('lang_forsecurity', _MD_MYDOWNLOADS_FORSECURITY);
	$xoopsTpl->assign('lang_cancel', _MD_MYDOWNLOADS_CANCEL);
	//ver3.0
	//wanikoo theme changer
	$xoopsTpl->assign("lang_themechanger", _MD_MYDOWNLOADS_THEMECHANGER);
	$mymydownloadstheme_options = '';

    	foreach ($GLOBALS['mydownloads_allowed_theme'] as $mymydownloadstheme) {
        $mymydownloadstheme_options .= '<option value="'.$mymydownloadstheme.'"';
        if ($mymydownloadstheme == $GLOBALS['mydownloads_theme']) {
            $mymydownloadstheme_options .= ' selected="selected"';
        }
        $mymydownloadstheme_options .= '>'.$mymydownloadstheme.'</option>';
    	}

    	$mydownloadstheme_select = '<select name="mydownloads_theme_select" onchange="submit();" size="1">'.$mymydownloadstheme_options.'</select>';

	$xoopsTpl->assign("mydownloadsthemeoption", $mydownloadstheme_select);
	//wanikoo search
	if ( file_exists(XOOPS_ROOT_PATH."/language/".$xoopsConfig['language']."/search.php") ) {
   	include_once XOOPS_ROOT_PATH."/language/".$xoopsConfig['language']."/search.php";
	} else {
  	include_once XOOPS_ROOT_PATH."/language/english/search.php";
	}
	$xoopsTpl->assign('lang_all', _SR_ALL);
	$xoopsTpl->assign('lang_any', _SR_ANY);
	$xoopsTpl->assign('lang_exact', _SR_EXACT);
	$xoopsTpl->assign('lang_search', _SR_SEARCH);
	$xoopsTpl->assign('module_id', $xoopsModule->getVar('mid'));

	//category head
	$catarray = array();
	if ( $mydownloads_show_letters ) {
	$catarray['letters'] = md_wfd_letters();
	}
	if ( $mydownloads_show_toolbar ) {
	$catarray['toolbar'] = md_wfd_toolbar();
	}
	$xoopsTpl->assign('catarray', $catarray);

	include_once dirname( __FILE__ )."/footer.php";

}

?>